package cn.bytecollege.controller;

import cn.bytecollege.service.RoomService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RoomDeleteController",value = "/roomDelete")
public class RoomDeleteController extends HttpServlet {
    private RoomService roomService = null;

    public RoomDeleteController(){
        roomService = new RoomService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收参数
        String id = request.getParameter("id");
        Integer roomId = Integer.valueOf(id);

        roomService.deleteById(roomId);

        //为了防止刷新时重复删除不存在的数据，此处用重定向跳转页面
        response.sendRedirect(request.getContextPath() + "/roomList");
    }
}
